// --------------------------------------------------------------------------------------------------------------------
// <copyright file="FormatDocumentationHeader.cs" company="StyleCop for ReSharper Development Team">
//   Copyright (c) StyleCop for ReSharper Development Team. All rights reserved.
// </copyright>
// <summary>
//   Defines the FormatDocumentationHeader type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace StyleCop.For.ReSharper.BulbItems.Spacing
{
    #region Using Directives

    using System.Text.RegularExpressions;

    using JetBrains.ProjectModel;
    using JetBrains.TextControl;

    using StyleCop.For.ReSharper.BulbItems.Framework;

    #endregion

    /// <summary>
    /// BulbItem - FormatDocumentationHeader : Fixes documention headers.
    /// </summary>
    internal class FormatDocumentationHeader : QuickFixBulbItem
    {
        #region Public Methods

        /// <summary>
        /// Performs the QuickFix, inserts the configured modifier into the location specified by
        /// the violation.
        /// </summary>
        /// <param name="solution">
        /// Current Solution.
        /// </param>
        /// <param name="textControl">
        /// Current Text Control to modify.
        /// </param>
        public override void ExecuteInner(ISolution solution, ITextControl textControl)
        {
            var documentation = this.DocumentRange.GetText();
            var regEx = new Regex("(((///[ ^ ] *)|\"))|((///))");
            documentation = regEx.Replace(documentation, "/// ");
            textControl.Document.ReplaceText(this.DocumentRange.TextRange, documentation);
        }

        #endregion
    }
}